package com.design.movieticket.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.movieticket.entity.Suggestion;
import com.design.movieticket.mapper.SuggestionMapper;
import com.design.movieticket.service.SuggestionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SuggestionServiceImpl extends ServiceImpl<SuggestionMapper, Suggestion> implements SuggestionService {
    @Resource
    private SuggestionMapper suggestionMapper;

    /** 分页查询 */
    @Override
    public LambdaQueryWrapper buildQuery(Suggestion suggestion) {
        LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery(Suggestion.class)
                .eq(StringUtils.isNotBlank(suggestion.getUsername()),Suggestion::getUsername,suggestion.getUsername());
        return lambdaQueryWrapper;
    }

    /** 分页相关 */
    @Override
    public <E extends IPage<Suggestion>> E page(E page, Wrapper<Suggestion> queryWrapper) {
        return super.page(page, queryWrapper);
    }

    /** 新增或更新建议数据 */
    @Override
    public void addOrUpdateSuggestionInfo(Suggestion suggestion) {
        super.saveOrUpdate(suggestion);
    }

    /** 获取建议信息详情 */
    @Override
    public Suggestion getSuggestionDetail(long id) {
        return super.getById(id);
    }

    /** 删除建议信息 */
    @Override
    public void delSuggestionById(long id) {
        super.removeById(id);
    }
}
